#include <iostream>
#include <fstream>
using namespace std;

void test1()
{
    ofstream outfile("test_ofstream.txt", ofstream::app);
    outfile << "hello" << endl;
    outfile.close();
}

void test2()
{
    char data[1024];

    // 以写模式打开文件
    ofstream outfile;
    outfile.open("demo.txt");
    cout <<"Writing to the file"<<endl;
    cin.getline(data,1024);

    //向文件写入用户输入的数据
    outfile<<data<<endl;
    //关闭打开的文件
    outfile.close();
}

void test3()
{
    char data[1024];
    //从文件读取信息，并将其输出到屏幕上
    ifstream infile;
    infile.open("demo.txt");
    for(int i = 0; i < 3; ++i)
    {
        infile >> data;
        cout << data << endl;
    }
    infile.close();
}

int main()
{
    //test2();
    test3();
    return 0;
}